package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.*;
import com.sky.entity.Orders;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.repository.query.Param;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {


    /**
     * 插入订单数据
     * @param order
     */
    void insert(Orders order);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    @Update("update orders set status = #{OrderStatus},pay_status=#{OrderPaidStatus},checkout_time = #{payTime}where number = #{orderNumber}")
    void update1(Integer OrderPaidStatus,Integer OrderStatus,LocalDateTime payTime,String orderNumber);

    @Select("select count(*) from orders")
    long count();

    List<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    @Update("update orders set status = 6,rejection_reason = #{rejectionReason} where id = #{id}")
    void rejection(OrdersRejectionDTO ordersRejectionDTO);


    @Select("select count(*) from orders where user_id = #{currentId}")
    long countById(Long currentId);

    List<OrderVO> pageQueryById(Integer Page, Integer pageSize, Integer status);

    @Update("update orders set status = #{status} where id = #{id}")
    void ConfirmOrder(OrdersConfirmDTO ordersConfirmDTO);

    @Update("update orders set status = 4 where id = #{id}")
    void deliver(Long id);

    @Update("update orders set status = 5,delivery_time = now() where id = #{id}")
    void complete(Long id);

    @Update("update orders set status = 6,cancel_reason = #{cancelReason},cancel_time = NOW()  where id = #{id}")
    void cancel(OrdersCancelDTO ordersCancelDTO);

    OrderStatisticsVO statistics();

    @Select("select count(status) from orders where status = #{i}")
    Integer countNumber(int i);

    @Update("update orders set status = 6,cancel_reason = #{s} where id = #{id}")
    void cancelById(Long id,String s);

    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> getByStatusAndOrderTime(Integer status, LocalDateTime orderTime);



    void updateOrders(Orders order);
}
